package com.officegame;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class PlayersActivity extends Activity {

	private Button btnSearch;
	private TextView tvOutput;
	private OfficeGameApplication app;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_activity_players);

		app = (OfficeGameApplication) getApplication();
		
		mapUI();
		setListeners();
	}

	private void mapUI() {
		btnSearch = (Button) findViewById(R.id.btn_search);
		tvOutput = (TextView) findViewById(R.id.tv_output);
	}

	private void setListeners() {
		btnSearch.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				new SearchAsync().execute();
			}
		});

	}

	private class SearchAsync extends AsyncTask {
		private String output;

		@Override
		protected Object doInBackground(Object... params) {
			output = app.getRestClient().getGameTables().get(0).toString();
			return null;
		}

		@Override
		protected void onPostExecute(Object result) {
			super.onPostExecute(result);
			tvOutput.setText(output);
		}

	}

}
